<?php
/***************************************************************************
 *
 *   copyright            : (C) 2011 Winds of Storm
 *
 *   $Id: misc.php 131 2011-06-12 20:24:56Z stormerider $
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

$misc_commands	= array('TYPE'		=>	'command',
			'NAME'		=>	'Misc. Commands',
			'VERSION'	=>	'0.0.1',
			'CREDIT'	=>	'StormeRider',
			'FUNC'		=>	'pluginMiscCommands',
			'HELP'		=>	'pluginMiscCommandsHelp');
$plugins[]	= $misc_commands;

function pluginMiscCommandsHelp($help) {
	global	$misc_commands;

	$help['random1']	= array("/random [number]",
					"Roll a random number between 0 and [number]" .
					pluginCredit($misc_commands));
	$help['random2']	= array("/random [number1] [number2]",
					"Roll a random number between [number1] and [number2]" .
					pluginCredit($misc_commands));
	$help['cleanup']	= array("/cleanup",
					"Remove junk events from the database (ping responses, help entries, etc.)".
					pluginCredit($misc_commands));

	return $help;
}

function pluginMiscCommands($userinfo, $event) {
	global	$p_row;
	global	$db;
	global	$dbprefix;

        $username       = $userinfo['username'];
        $userid         = $userinfo['userid'];
        $isMod          = $userinfo['isMod'];
	$msg		= $event[0]['msg'];

	if ((eregi("^/random", $msg))) {
		$event[0]['parsed']	= 1;
		$random	= explode(" ", $msg);
		$num1	= $random[1];
		$num2	= $random[2];
		if (is_numeric($num1) && is_numeric($num2)) {
			$x			= rand($num1, $num2);
			$event[0]['msg']	= addslashes("<span class=sysmsg><i>*** $username rolls a dice between $num1 and $num2: <b>$x</b></i></span>");
		} else if (is_numeric($num1)) {
			$x			= rand(0, $num1);
			$event[0]['msg']	= addslashes("<span class=sysmsg><i>*** $username rolls a dice between 0 and $num1: <b>$x</b></i></span>");
		} else if (is_numeric($num2)) {
			$x			= rand(0, $num2);
			$event[0]['msg']	= addslashes("<span class=sysmsg><i>*** $username rolls a dice between 0 and $num2: <b>$x</b></i></span>");
		} else {
			$event[0]['room']	= 0;
			$event[0]['userto']	= $userid;
			$event[0]['msg']	= addslashes("<span class=sysmsg><b>*** ERROR: '$num1' and '$num2' are not valid numbers to roll with</b></span>");
		}
        } else if (eregi("^/cleanup", $msg)) {
		$event[0]['parsed']	= 1;
		$sql	= "DELETE FROM {$dbprefix}events WHERE user_id_from=user_id_to AND user_id_to=$userid AND room_id_to=0";
		$res	= $db->sql_query($sql);
		
		$event[0]['room']	= 0;
		$event[0]['userto']	= $userid;
		$event[0]['msg']	= "<span class=sysmsg><b>*** Removed junk messages.</b></span>";
	}
}
?>
